﻿using System;
using System.Web.Services;
using Monkey.Warrenty.Biz;
using Monkey.Warrenty.EntityModel;

namespace MonkeyWarranty.Web.Manufacturers
{
    public partial class List : System.Web.UI.Page
    {
        #region Properties

        private static ManufacturerBiz _manufacturerBiz;
        private static ManufacturerBiz ManufacturerManager
        {
            get { return _manufacturerBiz ?? (_manufacturerBiz = new ManufacturerBiz()); }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var groups = ManufacturerManager.GetAllManufacturerGroups();
                groups.Insert(0, new ManufacturerGroup { Id = 0, Name = Resources.GlobalStrings.AllGroups });

                ddlManufacturerGroups.DataTextField = "Name";
                ddlManufacturerGroups.DataValueField = "Id";
                ddlManufacturerGroups.DataSource = groups;
                ddlManufacturerGroups.DataBind();
            }
        }

        #region Manufacturer methods

        [WebMethod(EnableSession = true)]
        public static object ManufacturerListByFilter(string name, int manufacturerGroupId, int jtStartIndex, int jtPageSize, string jtSorting)
        {
            return ManufacturerManager.ManufacturerListByFilterWs(name, manufacturerGroupId, jtStartIndex, jtPageSize, jtSorting);
        }

        [WebMethod(EnableSession = true)]
        public static object CreateManufacturer(Manufacturer record)
        {
            return ManufacturerManager.CreateManufacturerWs(record);
        }

        [WebMethod(EnableSession = true)]
        public static object UpdateManufacturer(Manufacturer record)
        {
            return ManufacturerManager.UpdateManufacturerWs(record);
        }

        [WebMethod(EnableSession = true)]
        public static object DeleteManufacturer(int Id)
        {
            return ManufacturerManager.DeleteManufacturerWs(Id);
        }

        #endregion

        #region CusmtomerGroup methods

        [WebMethod(EnableSession = true)]
        public static object GetManufacturerGroupOptions()
        {
            return ManufacturerManager.GetManufacturerGroupOptionsWs();
        }

        #endregion
    }
}